<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
 
// import Joomla view library
jimport('joomla.application.component.view');
jimport( 'joomla.application.application' );
/**
 * HTML View class for the HelloWorld Component
 */
class TinTucViewTinTuc extends JViewLegacy
{
         // Overwriting JView display method
        public function display($tpl = null) 
        {
				$app = JFactory::getApplication();
				$this->document = JFactory::getDocument();
				$model =  $this->getModel('tintuc');

				//$state 		= $this->get('State');
				//$this->params = &$state->params;
				// $catID = JRequest::getVar('id',20);
				$catID = $model->getCatID();
				$this->subID = JRequest::getVar('Subid',0);
				$option = JRequest::getVar('option',0);
				$itemid = JRequest::getVar('Itemid',0);
				$categories = JCategories::getInstance('Content');
				$this->_parent = $categories->get((int) $catID);
				$this->sitename = $app->getCfg('sitename');
				$this->title = $this->document->getTitle();
				
				if(is_object($this->_parent))
				{
					$this->_items = $this->_parent->getChildren(false);
					if(isset($this->_items[0]) && empty($this->subID))
						$this->subID = $this->_items[0]->id;
				}
				else
				{
					$this->_items = false;
				}	
				
				$this->params = JComponentHelper::getParams('com_content');
				$limit = $this->params->get('num_intro_articles');
				$prefix = "Itemid=$itemid&";
				$data = $model->getItems($this->subID,$limit,$prefix);
				$this->items = $data['rows'];
				$this->pagination = $data['pagination'];
				
				
				// $db = JFactory::getDbo();
				// $catid = $this->subID;
				// $query = "SELECT * FROM $db->quoteName('#__content') WHERE catid = $db->quote($catid)";
				// $db->setQuery($query);
				// $articles = $db->loadAssocList();
				
				// print_r($articles);
				// die;
				
				$this->option = $option;
				$this->itemID = $itemid;

                // Assign data to the view
                $this->msg = $this->get('Msg');
 
                // Check for errors.
                if (count($errors = $this->get('Errors'))) 
                {
                        JLog::add(implode('<br />', $errors), JLog::WARNING, 'jerror');
                        return false;
                }
                // Display the view
                parent::display($tpl);
        }
}